<template>
  <div class="mainsu">
    <div class="main_white padding10">
      <div class="mainor_form batch-wrap">
        <el-form
          :inline="true"
          :model="form"
          class="demo-form-inline"
          ref="userListFrom"
          label-width="90px"
          id="form"
        >
          <el-form-item label="关键字：" prop="keyword">
            <el-input
              v-model.trim="form.keyword"
              placeholder="用户名称/手机号码"
              clearable
              class="wid220"
            ></el-input>
          </el-form-item>
          <MainFormBtn @reset="reset" @getSearchFor="getArticleList" :loading="listLoading" :showBtn="false">
            </MainFormBtn>
        </el-form>
      </div>
      <div class="main_table">
        <el-table
          ref="multipleTable"
          class="mg-t-4"
          v-loading="listLoading"
          :data="list.data"
          element-loading-text="加载中"
          fit
          highlight-current-row
          :height="borderHeight"
          :header-cell-style="tableHeightStyle"
        >
          <el-table-column label="序号">
            <template slot-scope="scope">{{
              (current.page - 1) * current.per_page + scope.$index + 1
            }}</template>
          </el-table-column>
          <el-table-column
            label="用户名称"
            prop="nickname"
            class-name="main_hei"
          >
            <template slot-scope="scope">{{ scope.row.nickname }}</template>
          </el-table-column>
          <el-table-column label="手机号" prop="mobile" class-name="main_hei" />
          <el-table-column
            label="创建时间"
            prop="created_at"
            class-name="main_hei"
          >
            <template slot-scope="scope">
              {{ parseTime(scope.row.created_at, "{y}-{m}-{d}") }}
            </template>
          </el-table-column>
          <el-table-column
            label="管理操作"
            align="center"
            fixed="right"
            width="140"
            class-name="main_hei"
          >
            <template slot-scope="scope">
              <el-link type="warning" @click="knotClick(scope.row.id)"
                >恢复</el-link
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="main_page boxdq">
        <div></div>
        <!-- 分页 -->
        <div class="main_page_r">
          <MainPagination
            :current-page="current.page"
            :page-sizes="[20, 30, 50, 100]"
            :page-size="limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount"
            background
            @size-change="changeLimit"
            @current-change="changePage"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mixins } from "@/mixins/index.js";
import {
  recycle_member,
  recycle_recycleMember,
} from "@/api/global/globalRecycle";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime } from "@/utils/index";

export default {
  mixins: [mixins],
  components: {},
  data() {
    return {
      parseTime,
      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      // 列表数据
      list: {
        list: [],
      },
      listLoading: false,
      // 搜索
      form: {
        keyword: "",
      },
    };
  },
  created() {
    // 列表
    this.getNumerical(200);
    this.recycle_member();
  },
  methods: {
    reset() {
      this.$refs['userListFrom'].resetFields()
      this.recycle_member();
    },
    startGetting() {
      this.getArticleList();
    },
    // 恢复
    knotClick(id) {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id: id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: id }
      );
      recycle_recycleMember(data).then((res) => {
        if (res.errcode == 0) {
          this.$message({
            message: "恢复成功",
            type: "success",
          });
          this.recycle_member();
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.recycle_member();
    },
    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.recycle_member();
    },
    changePage(page) {
      this.current.page = page;
      this.recycle_member();
    },
    // 列表
    recycle_member() {
      this.listLoading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, this.list_form(), this.current)
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form(),
        this.current
      );
      recycle_member(data).then((res) => {
        console.log(res);
        this.listLoading = false;
        if (res.errcode == 0) {
          this.list = res.data.list;
          this.totalCount = res.data.list.total;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    list_form() {
      let form = JSON.parse(JSON.stringify(this.form));

      return form;
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.mainsu {
  .mainor_form form {
    width: calc(100% - 160px);
  }
  .mainor_form {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }
}
/deep/.el-form-item--small.el-form-item {
  margin-bottom: 10px;
}
</style>
